﻿using System;

namespace Utilities.Media.Audio
{
    public class AudioBuffer
    {
        public byte[] Data { get; protected set; }

        public int NumChannels { get; protected set; }
        public int BitsPerSample { get; protected set; }
        public int SampleRate { get; protected set; }

        public int NumSamples
        {
            get
            {
                return Data.Length / (NumChannels * BitsPerSample / 8);
            }
        }
        public TimeSpan Duration
        {
            get
            {
                return new TimeSpan((long)(NumSamples / (float)SampleRate * 10000000));
            }
        }

        public AudioBuffer(short numChannels, short bitsPerSample, int sampleRate, TimeSpan duration)
        {
            NumChannels = numChannels;
            BitsPerSample = bitsPerSample;
            SampleRate = sampleRate;
            
            int length = (int)(sampleRate * numChannels * bitsPerSample / 8 * duration.TotalMilliseconds / 1000);
            length -= length % (numChannels * bitsPerSample / 8);

            Data = new byte[length];
        }
    }
}